package com.ruzin.diplomska;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URI;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;

public class ServerConnection {

	public static String getUserPass(String User, String Pass) {
		return "http://10.0.2.2:8080/ZavrsenProekt/faces/loginProverka.do?usrnm="
				+ User + "&pass=" + Pass;
	}

	public static String bookTimeDate(String datum, String vreme, String user, String pass) {
		return "http://10.0.2.2:8080/ZavrsenProekt/faces/loginProverka.do?usrnm="
				+ user + "&pass=" + pass + "&datum="
				+ datum + "&vreme=" + vreme;
	}

	public static boolean isConnectionOK(String site) {
		try {
			HttpGet request = new HttpGet();
			request.setURI(new URI(site));
			return true;
		} catch (Exception e) {
			return false;
		}
	}

	public static String getInfo(String site) {
		BufferedReader in = null;
		try {
			HttpClient client = new DefaultHttpClient();
			HttpGet request = new HttpGet();
			request.setHeader("User-Agent", "Koga_na_zabar");
			request.setURI(new URI(site));
			HttpResponse response = client.execute(request);
			in = new BufferedReader(new InputStreamReader(response.getEntity()
					.getContent()));
			StringBuffer sb = new StringBuffer("");
			String line = "";
			String NL = System.getProperty("line.separator");
			while ((line = in.readLine()) != null) {
				sb.append(line + NL);
			}
			in.close();
			String page = sb.toString();
			return page;
		} catch (Exception e) {
			return "Error:" + e.getMessage();
		}
	}
	
}
